package kburndown.client.service
{
	import flash.geom.Point;
	import flash.utils.clearTimeout;
	import flash.utils.setTimeout;
	
	import mx.controls.ToolTip;
	import mx.core.FlexGlobals;
	import mx.managers.ToolTipManager;

	public class ServiceToolTip
	{
		public function ServiceToolTip()
		{
		}
		
		private static var _tooltipMap: Object = {};
		_tooltipMap[KBurndownService.Method_AddTask] = "正在增加任务...";
		_tooltipMap[KBurndownService.Method_EditTask] = "正在修改任务...";
		_tooltipMap[KBurndownService.Method_DeleteTask] = "正在删除任务...";
		_tooltipMap[KBurndownService.Method_FinishTask] = "将任务标记为已完成 ...";
		_tooltipMap[KBurndownService.Method_MoveTask] = "正在调整任务优先级...";
		_tooltipMap[KBurndownService.Method_MoveUnit] = "正在提交数据";
		private static var _tooltip: ToolTip;
		private static var _showTime: Number;
		private static var _hideToken: uint;
		
		public static function showTooltip(method: String): void
		{
			var value: String = getToolTipbyMethod(method);
			if (FlexGlobals.topLevelApplication.visible)
			{
				var point: Point = new Point(FlexGlobals.topLevelApplication.width / 2, 50);
				if (!_tooltip)
				{
					_tooltip = ToolTipManager.createToolTip(value, point.x, point.y) as ToolTip;
				}
				clearTimeout(_hideToken);
				_tooltip.horizontalCenter = 0;
				_tooltip.y = point.y;
				_tooltip.styleName = "serviceToolTip";
				
				_tooltip.text = value;
				_showTime = new Date().time;
			}
		}
		
		public static function hideToolTip(): void
		{
			var date: Date = new Date();
			if (date.time - _showTime < 1000)
				_hideToken = setTimeout(_hideToolTip, 1000);
			else
				_hideToolTip();
			function _hideToolTip(): void
			{
				if (_tooltip)
					ToolTipManager.destroyToolTip(_tooltip);
				_tooltip = null;
			}
		}
		
		public static function getToolTipbyMethod(method: String): String
		{
			if (_tooltipMap[method])
				return _tooltipMap[method];
			else
				return "正在读取中";
		}
	}
}